<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
/**
 * Class CertifiedDrivingAgent
 * Desc  认证代驾Model
 * Create on 2024/10/26 10:39
 * Create by wangyafang
 */

namespace app\api\model\wddj\trailer;


use addons\wddj\library\IDCardEncryptor;
use app\api\model\wddj\UserWechat;
use think\Model;

class CertifiedDrivingAgent extends Model
{
// 表名
    protected $name = 'wddj_certified_driving_agent_trailer';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    protected static function init()
    {
        self::beforeInsert(function ($row) {
            $row->mobile = (new UserWechat())->where('id',$row['wechat_id'])->value('mobile');
        });
    }

    public function getIdCardAttr($value)
    {
        $row = self::where('id_card',$value)->find();
        $configObj = (new \app\api\model\wddj\Config())->get(1);
        $encryptor = new IDCardEncryptor($configObj['encryptor_key'],$configObj['encryptor_iv']);
        $value = $encryptor->decrypt($value);
        if ($row['state'] != '3') {
            $value = substr_replace($value, '**********', 4,10);
        }
        return $value;
    }

    protected function getFrontIdCardAttr($value)
    {
        return wddj_full_url($value);
    }

    protected function getFrontVehicleDriverLicenseAttr($value)
    {
        return wddj_full_url($value);
    }

    protected function setFrontIdCardAttr($value)
    {
        $value = remove_wddj_full_url($value);
        return $value;
    }

    protected function setFrontVehicleDriverLicenseAttr($value)
    {
        $value = remove_wddj_full_url($value);
        return $value;
    }
}



 